$(function($) {
	var logoutUrl = "/logOut"; //退出系统的网址
	var homeUrl = "/indexHome"; //主页的网址
	var editPasswordUrl = "/Home/Account/update"; //修改用户密码的网址


	$('[data-rel=tooltip]').tooltip({
		'container': 'body'
	}); //初始化提示
	//切换配置框是否可见
	$('#id-toggle-setting').on('click', function(event) {
		//		console.log(event.target);
		event.preventDefault();
		$('#ace-settings-box').toggleClass('open');
	});
	//	$("html").click(function(event) {
	//		$('#ace-settings-box').removeClass('open');	
	//	});

	//-----------------菜单操作-----------------
	var globalMenu = new GlobalMenu();
	globalMenu.init();

	//-----------------按钮小图标操作-----------------
	//点击主页按钮
	$("#id-btn-home").on("click", function(e) {
//		General.stopEvent(e);
		var url = $(this).attr('data-url');
		homeUrl = url || homeUrl;
		var breadcrumbData = [];
		var obj;
		obj = {
			"id": "1",
			"text": "首页",
			"href": homeUrl,
		};
		breadcrumbData.push(obj);
		showBreadcrumb(breadcrumbData);
		$("#top-container").attr("src", homeUrl);
	});
	//点击刷新按钮
	$("#id-btn-refresh").on("click", function(e) {
		General.stopEvent(e);
		globalMenu.refresh();
	});
	//点击修改密码按钮
	$("#id-btn-edit-password,#id-a-edit-password").on("click", function(e) {
//		General.stopEvent(e);
		var url = $(this).attr('data-url');
		editPasswordUrl = url || editPasswordUrl;
		var breadcrumbData = [];
		var obj;
		obj = {
			"id": "1",
			"text": "编辑帐号",
			"href": editPasswordUrl
		};
		breadcrumbData.push(obj);
		showBreadcrumb(breadcrumbData);
		$("#top-container").attr("src", editPasswordUrl);
	});
	//点击退出按钮
	$("#id-btn-exit,#id-a-exit").on("click", function(e) {
		General.stopEvent(e);
		var url = $(this).attr('data-url');
		if(url && url!='#'){
			logoutUrl = url;
		}
		General.confirm("您确定要退出系统吗?", null, exitSystem);
	});

	//退出系统
	function exitSystem() {
		window.location.href = logoutUrl;
	};

	/**
	 * 显示导航
	 * @param {Object} menuData 菜单数据来源
	 */
	function showBreadcrumb(menuData) {
		var str = "";
		var self = this;
		$.each(menuData, function(index, obj) {
			if (index < menuData.length - 1) {
				str += "<li>";
			} else {
				str += "<li class=\"active\">";
			}
			if (index == 0)
				str += "<i class=\"ace-icon fa fa-home home-icon\"></i>";
			if (index < menuData.length - 1) {
				str += "<a remark=\"" + obj.id + "\" href=\"" + obj.href + "\" target=\"top-container\">" + obj.text + "</a>";
			} else {
				str += "<a remark=\"" + obj.id + "\" href=\"" + obj.href + "\" target=\"top-container\">" + obj.text + "</a>";
				//					str += obj.text;
			}

			str += "</li>";
		});
		$("#id-breadcrumb a").off();
		$("#id-breadcrumb").html(str);
	};

	//--------------动态调整窗口大小
	adjustIframe();

	function adjustIframe() {
		var height = $(window).height();
		var pos = $("#iframe-container").position();
		$("#iframe-container").css("height", (height - pos.top) + "px");
	}
	$(window).resize(adjustIframe);
});